home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / Libraries / Apache 1.0 / src / http_core.c < prev    next >
Text File  |  1995-12-04  |  23KB  |  705 lines

  1.  
  2. /* ====================================================================
  3.  * Copyright (c) 1995 The Apache Group.  All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that the following conditions
  7.  * are met:
  8.  *
  9.  * 1. Redistributions of source code must retain the above copyright
  10.  *    notice, this list of conditions and the following disclaimer. 
  11.  *
  12.  * 2. Redistributions in binary form must reproduce the above copyright
  13.  *    notice, this list of conditions and the following disclaimer in
  14.  *    the documentation and/or other materials provided with the
  15.  *    distribution.
  16.  *
  17.  * 3. All advertising materials mentioning features or use of this
  18.  *    software must display the following acknowledgment:
  19.  *    "This product includes software developed by the Apache Group
  20.  *    for use in the Apache HTTP server project (http://www.apache.org/)."
  21.  *
  22.  * 4. The names "Apache Server" and "Apache Group" must not be used to
  23.  *    endorse or promote products derived from this software without
  24.  *    prior written permission.
  25.  *
  26.  * 5. Redistributions of any form whatsoever must retain the following
  27.  *    acknowledgment:
  28.  *    "This product includes software developed by the Apache Group
  29.  *    for use in the Apache HTTP server project (http://www.apache.org/)."
  30.  *
  31.  * THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
  32.  * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  33.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  34.  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE APACHE GROUP OR
  35.  * IT'S CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  36.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  37.  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  38.  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  39.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  40.  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  41.  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  42.  * OF THE POSSIBILITY OF SUCH DAMAGE.
  43.  * ====================================================================
  44.  *
  45.  * This software consists of voluntary contributions made by many
  46.  * individuals on behalf of the Apache Group and was originally based
  47.  * on public domain software written at the National Center for
  48.  * Supercomputing Applications, University of Illinois, Urbana-Champaign.
  49.  * For more information on the Apache Group and the Apache HTTP server
  50.  * project, please see <http://www.apache.org/>.
  51.  *
  52.  */
  53.  
  54.  
  55. #define CORE_PRIVATE
  56. #include "httpd.h"
  57. #include "http_config.h"
  58. #include "http_core.h"
  59. #include "http_protocol.h"    /* For index_of_response().  Grump. */
  60. #include "http_conf_globals.h"
  61.  
  62. #include "http_main.h"        /* For the default_handler below... */
  63. #include "http_log.h"
  64.  
  65. /* Server core module... This module provides support for really basic
  66.  * server operations, including options and commands which control the
  67.  * operation of other modules.  Consider this the bureaucracy module.
  68.  *
  69.  * The core module also defines handlers, etc., do handle just enough
  70.  * to allow a server with the core module ONLY to actually serve documents
  71.  * (though it slaps DefaultType on all of 'em); this was useful in testing,
  72.  * but may not be worth preserving.
  73.  *
  74.  * This file could almost be mod_core.c, except for the stuff which affects
  75.  * the http_conf_globals.
  76.  */
  77.  
  78. void *create_core_dir_config (pool *a, char *dir)
  79. {
  80.     core_dir_config *conf =
  81.       (core_dir_config *)pcalloc(a, sizeof(core_dir_config));
  82.   
  83.     if (!dir || dir[strlen(dir) - 1] == '/') conf->d = dir;
  84.     else conf->d = pstrcat (a, dir, "/", NULL);
  85.  
  86.     conf->opts = dir ? OPT_UNSET : OPT_ALL;
  87.     conf->override = dir ? OR_UNSET : OR_ALL;
  88.  
  89.     return (void *)conf;
  90. }
  91.  
  92. void *merge_core_dir_configs (pool *a, void *basev, void *newv)
  93. {
  94.     core_dir_config *base = (core_dir_config *)basev;
  95.     core_dir_config *new = (core_dir_config *)newv;
  96.     core_dir_config *conf =
  97.       (core_dir_config *)pcalloc (a, sizeof(core_dir_config));
  98.     int i;
  99.   
  100.     memcpy ((char *)conf, (const char *)base, sizeof(core_dir_config));
  101.     
  102.     conf->d = new->d;
  103.     
  104.     if (new->opts != OPT_UNSET) conf->opts = new->opts;
  105.     if (new->override != OR_UNSET) conf->override = new->override;
  106.     if (new->default_type) conf->default_type = new->default_type;
  107.     
  108.     if (new->auth_type) conf->auth_type = new->auth_type;
  109.     if (new->auth_name) conf->auth_name = new->auth_name;
  110.     if (new->requires) conf->requires = new->requires;
  111.  
  112.     for (i = 0; i <= RESPONSE_CODES; ++i)
  113.         if (new->response_code_strings[i] != NULL)
  114.        conf->response_code_strings[i] = new->response_code_strings[i];
  115.  
  116.     return (void*)conf;
  117. }
  118.  
  119. void *create_core_server_config (pool *a, server_rec *s)
  120. {
  121.     core_server_config *conf =
  122.       (core_server_config *)pcalloc(a, sizeof(core_server_config));
  123.     int is_virtual = is_virtual_server (s);
  124.   
  125.     conf->access_name = is_virtual ? NULL : DEFAULT_ACCESS_FNAME;
  126.     conf->document_root = is_virtual ? NULL : DOCUMENT_LOCATION;
  127.     conf->sec = make_array (a, 40, sizeof(void *));
  128.     
  129.     return (void *)conf;
  130. }
  131.  
  132. void *merge_core_server_configs (pool *p, void *basev, void *virtv)
  133. {
  134.     core_server_config *base = (core_server_config *)basev;
  135.     core_server_config *virt = (core_server_config *)virtv;
  136.     core_server_config *conf = 
  137.     (core_server_config *)pcalloc(p, sizeof(core_server_config));
  138.  
  139.     *conf = *virt;
  140.     if (!conf->access_name) conf->access_name = base->access_name;
  141.     if (!conf->document_root) conf->document_root = base->document_root;
  142.     conf->sec = append_arrays (p, virt->sec, base->sec);
  143.  
  144.     return conf;
  145. }
  146.  
  147. /* Add per-directory configuration entry (for <directory> section);
  148.  * these are part of the core server config.
  149.  */
  150.  
  151. void add_per_dir_conf (server_rec *s, void *dir_config)
  152. {
  153.     core_server_config *sconf = get_module_config (s->module_config,
  154.                            &core_module);
  155.     void **new_space = (void **) push_array (sconf->sec);
  156.     
  157.     *new_space = dir_config;
  158. }
  159.  
  160. /*****************************************************************
  161.  *
  162.  * There are some elements of the core config structures in which
  163.  * other modules have a legitimate interest (this is ugly, but necessary
  164.  * to preserve NCSA back-compatibility).  So, we have a bunch of accessors
  165.  * here...
  166.  */
  167.  
  168. int allow_options (request_rec *r)
  169. {
  170.     core_dir_config *conf = 
  171.       (core_dir_config *)get_module_config(r->per_dir_config, &core_module); 
  172.  
  173.     return conf->opts; 
  174.  
  175. int allow_overrides (request_rec *r) 
  176.     core_dir_config *conf = 
  177.       (core_dir_config *)get_module_config(r->per_dir_config, &core_module); 
  178.  
  179.     return conf->override; 
  180.  
  181. char *auth_type (request_rec *r)
  182. {
  183.     core_dir_config *conf = 
  184.       (core_dir_config *)get_module_config(r->per_dir_config, &core_module); 
  185.  
  186.     return conf->auth_type;
  187. }
  188.  
  189. char *auth_name (request_rec *r)
  190. {
  191.     core_dir_config *conf = 
  192.       (core_dir_config *)get_module_config(r->per_dir_config, &core_module); 
  193.  
  194.     return conf->auth_name;
  195. }
  196.  
  197. char *default_type (request_rec *r)
  198. {
  199.     core_dir_config *conf = 
  200.       (core_dir_config *)get_module_config(r->per_dir_config, &core_module); 
  201.  
  202.     return conf->default_type ? conf->default_type : DEFAULT_TYPE;
  203. }
  204.  
  205. char *document_root (request_rec *r) /* Don't use this!!! */
  206. {
  207.     core_server_config *conf = 
  208.       (core_server_config *)get_module_config(r->server->module_config,
  209.                           &core_module); 
  210.  
  211.     return conf->document_root;
  212. }
  213.  
  214. array_header *requires (request_rec *r)
  215. {
  216.     core_dir_config *conf = 
  217.       (core_dir_config *)get_module_config(r->per_dir_config, &core_module); 
  218.  
  219.     return conf->requires;
  220. }
  221.  
  222.  
  223. /* Should probably just get rid of this... the only code that cares is
  224.  * part of the core anyway (and in fact, it isn't publicised to other
  225.  * modules).
  226.  */
  227.  
  228. char *response_code_string (request_rec *r, int error_index)
  229. {
  230.     core_dir_config *conf = 
  231.       (core_dir_config *)get_module_config(r->per_dir_config, &core_module); 
  232.  
  233.     return conf->response_code_strings[error_index];
  234. }
  235.  
  236. /*****************************************************************
  237.  *
  238.  * Commands... this module handles almost all of the NCSA httpd.conf
  239.  * commands, but most of the old srm.conf is in the the modules.
  240.  */
  241.  
  242. char *set_access_name (cmd_parms *cmd, void *dummy, char *arg)
  243. {
  244.     void *sconf = cmd->server->module_config;
  245.     core_server_config *conf = get_module_config (sconf, &core_module);
  246.   
  247.     conf->access_name = arg;
  248.     return NULL;
  249. }
  250.  
  251. char *set_document_root (cmd_parms *cmd, void *dummy, char *arg)
  252. {
  253.     void *sconf = cmd->server->module_config;
  254.     core_server_config *conf = get_module_config (sconf, &core_module);
  255.   
  256.     if (!is_directory (arg)) return "DocumentRoot must be a directory";
  257.     
  258.     conf->document_root = arg;
  259.     return NULL;
  260. }
  261.  
  262. char *set_error_document (cmd_parms *cmd, core_dir_config *conf, char *line)
  263. {
  264.     int error_number, index_number;
  265.     char *w;
  266.                 
  267.     /* 1st parameter should be a 3 digit number, which we recognize;
  268.      * convert it into an array index
  269.      */
  270.   
  271.     w = getword_conf (cmd->pool, &line);
  272.     error_number = atoi(w);
  273.     index_number = index_of_response(error_number);
  274.   
  275.     if (index_number < 0)
  276.         return pstrcat (cmd->pool, "Illegal HTTP response code ", w, NULL);
  277.                 
  278.     /* Nuke trailing '"', if present */
  279.     
  280.     if (line[strlen(line) - 1] == '"') line[strlen(line) - 1] = '\0';
  281.   
  282.     /* Store it... */
  283.  
  284.     conf->response_code_strings[index_number] = pstrdup (cmd->pool, line);
  285.  
  286.     return NULL;
  287. }
  288.  
  289. /* access.conf commands...
  290.  *
  291.  * The *only* thing that can appear in access.conf at top level is a
  292.  * <Directory> section.  NB we need to have a way to cut the srm_command_loop
  293.  * invoked by dirsection (i.e., <Directory>) short when </Directory> is seen.
  294.  * We do that by returning an error, which dirsection itself recognizes and
  295.  * discards as harmless.  Cheesy, but it works.
  296.  */
  297.  
  298. char *set_override (cmd_parms *cmd, core_dir_config *d, char *l)
  299. {
  300.     char *w;
  301.   
  302.     d->override = OR_NONE;
  303.     while(l[0]) {
  304.         w = getword_conf (cmd->pool, &l);
  305.     if(!strcasecmp(w,"Limit"))
  306.         d->override |= OR_LIMIT;
  307.     else if(!strcasecmp(w,"Options"))
  308.         d->override |= OR_OPTIONS;
  309.     else if(!strcasecmp(w,"FileInfo"))
  310.             d->override |= OR_FILEINFO;
  311.     else if(!strcasecmp(w,"AuthConfig"))
  312.         d->override |= OR_AUTHCFG;
  313.     else if(!strcasecmp(w,"Indexes"))
  314.             d->override |= OR_INDEXES;
  315.     else if(!strcasecmp(w,"None"))
  316.         d->override = OR_NONE;
  317.     else if(!strcasecmp(w,"All")) 
  318.         d->override = OR_ALL;
  319.     else 
  320.         return pstrcat (cmd->pool, "Illegal override option ", w, NULL);
  321.     }
  322.  
  323.     return NULL;
  324. }
  325.  
  326. char *set_options (cmd_parms *cmd, core_dir_config *d, char *l)
  327. {
  328.     d->opts = OPT_NONE;
  329.     while(l[0]) {
  330.         char *w = getword_conf(cmd->pool, &l);
  331.     if(!strcasecmp(w,"Indexes"))
  332.         d->opts |= OPT_INDEXES;
  333.     else if(!strcasecmp(w,"Includes"))
  334.         d->opts |= OPT_INCLUDES;
  335.     else if(!strcasecmp(w,"IncludesNOEXEC"))
  336.         d->opts |= (OPT_INCLUDES | OPT_INCNOEXEC);
  337.     else if(!strcasecmp(w,"FollowSymLinks"))
  338.         d->opts |= OPT_SYM_LINKS;
  339.     else if(!strcasecmp(w,"SymLinksIfOwnerMatch"))
  340.         d->opts |= OPT_SYM_OWNER;
  341.     else if(!strcasecmp(w,"execCGI"))
  342.         d->opts |= OPT_EXECCGI;
  343.     else if (!strcasecmp(w,"MultiViews"))
  344.         d->opts |= OPT_MULTI;
  345.     else if (!strcasecmp(w,"RunScripts")) /* AI backcompat. Yuck */
  346.         d->opts |= OPT_MULTI|OPT_EXECCGI;
  347.     else if(!strcasecmp(w,"None")) 
  348.         d->opts = OPT_NONE;
  349.     else if(!strcasecmp(w,"All")) 
  350.         d->opts = OPT_ALL;
  351.     else 
  352.         return pstrcat (cmd->pool, "Illegal option ", w, NULL);
  353.     }
  354.  
  355.     return NULL;
  356. }
  357.  
  358. char *require (cmd_parms *cmd, core_dir_config *c, char *arg)
  359. {
  360.     require_line *r;
  361.   
  362.     if (!c->requires)
  363.         c->requires = make_array (cmd->pool, 2, sizeof(require_line));
  364.     
  365.     r = (require_line *)push_array (c->requires);
  366.     r->requirement = pstrdup (cmd->pool, arg);
  367.     r->method_mask = cmd->limited;
  368.     return NULL;
  369. }
  370.  
  371. char *limit (cmd_parms *cmd, void *dummy, char *arg)
  372. {
  373.     char *limited_methods = getword(cmd->pool,&arg,'>');
  374.     int limited = 0;
  375.   
  376.     if (cmd->limited > 0) return "Can't nest <Limit> sections";
  377.     
  378.     while(limited_methods[0]) {
  379.         char *method = getword_conf (cmd->pool, &limited_methods);
  380.     if(!strcasecmp(method,"GET")) limited |= (1 << M_GET);
  381.     else if(!strcasecmp(method,"PUT")) limited |= (1 << M_PUT);
  382.     else if(!strcasecmp(method,"POST")) limited |= (1 << M_POST);
  383.     else if(!strcasecmp(method,"DELETE")) limited |= (1 << M_DELETE);
  384.     else return "unknown method in <Limit>";
  385.     }
  386.  
  387.     cmd->limited = limited;
  388.     return NULL;
  389. }
  390.  
  391. char *endlimit (cmd_parms *cmd, void *dummy, void *dummy2)
  392. {
  393.     if (cmd->limited == -1) return "</Limit> unexpected";
  394.     
  395.     cmd->limited = -1;
  396.     return NULL;
  397. }
  398.  
  399. static char *end_dir_magic = "</Directory> outside of any <Directory> section";
  400.  
  401. char *end_dirsection (cmd_parms *cmd, void *dummy) {
  402.     return end_dir_magic;
  403. }
  404.  
  405. char *dirsection (cmd_parms *cmd, void *dummy, char *arg)
  406. {
  407.     char *errmsg, *endp = strrchr (arg, '>');
  408.     int old_overrides = cmd->override;
  409.     char *old_path = cmd->path;
  410.     void *new_dir_conf = create_per_dir_config (cmd->pool);
  411.  
  412.     if (endp) *endp = '\0';
  413.  
  414.     if (cmd->path) return "<Directory> sections don't nest";
  415.     if (cmd->limited != -1) return "Can't have <Directory> within <Limit>";
  416.     
  417.     cmd->path = getword_conf (cmd->pool, &arg);
  418.     cmd->override = OR_ALL|ACCESS_CONF;
  419.  
  420.     errmsg = srm_command_loop (cmd, new_dir_conf);
  421.     add_per_dir_conf (cmd->server, new_dir_conf);
  422.     
  423.     cmd->path = old_path;
  424.     cmd->override = old_overrides;
  425.  
  426.     if (errmsg == end_dir_magic) return NULL;
  427.     return errmsg;
  428. }
  429.  
  430. /* httpd.conf commands... beginning with the <VirtualHost> business */
  431.  
  432. char *end_virthost_magic = "</Virtualhost> out of place";
  433.  
  434. char *end_virtualhost_section (cmd_parms *cmd, void *dummy) {
  435.     return end_virthost_magic;
  436. }
  437.  
  438. char *virtualhost_section (cmd_parms *cmd, void *dummy, char *arg)
  439. {
  440.     server_rec *main_server = cmd->server, *s;
  441.     char *errmsg, *endp = strrchr (arg, '>');
  442.     pool *p = cmd->pool, *ptemp = cmd->temp_pool;
  443.  
  444.     if (endp) *endp = '\0';
  445.     
  446.     if (is_virtual_server (main_server))
  447.     return "<VirtualHost> doesn't nest!";
  448.     
  449.     s = init_virtual_host (p, arg);
  450.     s->next = main_server->next;
  451.     main_server->next = s;
  452.     
  453.     cmd->server = s;
  454.     errmsg = srm_command_loop (cmd, s->lookup_defaults);
  455.     cmd->server = main_server;
  456.  
  457.     if (s->srm_confname)
  458.     process_resource_config (s, s->srm_confname, p, ptemp);
  459.  
  460.     if (s->access_confname)
  461.     process_resource_config (s, s->access_confname, p, ptemp);
  462.     
  463.     if (errmsg == end_virthost_magic) return NULL;
  464.     return errmsg;
  465. }
  466.  
  467. char *set_server_string_slot (cmd_parms *cmd, void *dummy, char *arg)
  468. {
  469.     /* This one's pretty generic... */
  470.   
  471.     int offset = (int)cmd->info;
  472.     char *struct_ptr = (char *)cmd->server;
  473.     
  474.     *(char **)(struct_ptr + offset) = pstrdup (cmd->pool, arg);
  475.     return NULL;
  476. }
  477.  
  478. char *server_type (cmd_parms *cmd, void *dummy, char *arg)
  479. {
  480.     if (!strcasecmp (arg, "inetd")) standalone = 0;
  481.     else if (!strcasecmp (arg, "standalone")) standalone = 1;
  482.     else return "ServerType must be either 'inetd' or 'standalone'";
  483.  
  484.     return NULL;
  485. }
  486.  
  487. char *server_port (cmd_parms *cmd, void *dummy, char *arg) {
  488.     cmd->server->port = atoi (arg);
  489.     return NULL;
  490. }
  491.  
  492. char *set_user (cmd_parms *cmd, void *dummy, char *arg) {
  493.     user_name = pstrdup (cmd->pool, arg);
  494.     user_id = uname2id (user_name);
  495.     return NULL;
  496. }
  497.  
  498. char *set_group (cmd_parms *cmd, void *dummy, char *arg) {
  499.     group_id = gname2id(arg);
  500.     return NULL;
  501. }
  502.  
  503. char *set_server_root (cmd_parms *cmd, void *dummy, char *arg) {
  504.     if (!is_directory (arg)) return "ServerRoot must be a valid directory";
  505.     strcpy (server_root, arg);
  506.     return NULL;
  507. }
  508.  
  509. char *set_timeout (cmd_parms *cmd, void *dummy, char *arg) {
  510.     cmd->server->timeout = atoi (arg);
  511.     return NULL;
  512. }
  513.  
  514. char *set_pidfile (cmd_parms *cmd, void *dummy, char *arg) {
  515.     pid_fname = pstrdup (cmd->pool, arg);
  516.     return NULL;
  517. }
  518.  
  519. char *set_idcheck (cmd_parms *cmd, void *dummy, int arg) {
  520.     cmd->server->do_rfc931 = arg;
  521.     return NULL;
  522. }
  523.  
  524. char *set_daemons_to_start (cmd_parms *cmd, void *dummy, char *arg) {
  525.     daemons_to_start = atoi (arg);
  526.     return NULL;
  527. }
  528.  
  529. char *set_min_free_servers (cmd_parms *cmd, void *dummy, char *arg) {
  530.     daemons_min_free = atoi (arg);
  531.     return NULL;
  532. }
  533.  
  534. char *set_max_free_servers (cmd_parms *cmd, void *dummy, char *arg) {
  535.     daemons_max_free = atoi (arg);
  536.     return NULL;
  537. }
  538.  
  539. char *set_server_limit (cmd_parms *cmd, void *dummy, char *arg) {
  540.     daemons_limit = atoi (arg);
  541.     return NULL;
  542. }
  543.  
  544. char *set_max_requests (cmd_parms *cmd, void *dummy, char *arg) {
  545.     max_requests_per_child = atoi (arg);
  546.     return NULL;
  547. }
  548.  
  549. char *set_bind_address (cmd_parms *cmd, void *dummy, char *arg) {
  550.     bind_address.s_addr = get_virthost_addr (arg, 1);
  551.     return NULL;
  552. }
  553.  
  554. /* Note --- change the mask below, and ErrorDocument will work from
  555.  * .htaccess files.  The question is, what AllowOverride should webmasters
  556.  * have to turn it off?
  557.  */
  558.  
  559. command_rec core_cmds[] = {
  560.  
  561. /* Old access config file commands */
  562.  
  563. { "<Directory", dirsection, NULL, RSRC_CONF, RAW_ARGS, NULL },
  564. { "</Directory>", end_dirsection, NULL, ACCESS_CONF, NO_ARGS, NULL },
  565. { "<Limit", limit, NULL, OR_ALL, RAW_ARGS, NULL },
  566. { "</Limit>", endlimit, NULL, OR_ALL, RAW_ARGS, NULL },
  567. { "AuthType", set_string_slot, (void*)XtOffsetOf(core_dir_config, auth_type),
  568.     OR_AUTHCFG, TAKE1, "an HTTP authorization type (e.g., \"Basic\")" },
  569. { "AuthName", set_string_slot, (void*)XtOffsetOf(core_dir_config, auth_name),
  570.     OR_AUTHCFG, RAW_ARGS, NULL },
  571. { "Require", require, NULL, OR_AUTHCFG, RAW_ARGS, NULL },
  572.     
  573. /* Old resource config file commands */
  574.   
  575. { "AccessFileName", set_access_name, NULL, RSRC_CONF, TAKE1, NULL },
  576. { "DocumentRoot", set_document_root, NULL, RSRC_CONF, TAKE1, NULL },
  577. { "ErrorDocument", set_error_document, NULL, RSRC_CONF, RAW_ARGS, NULL },
  578. { "AllowOverride", set_override, NULL, ACCESS_CONF, RAW_ARGS, NULL },
  579. { "Options", set_options, NULL, OR_OPTIONS, RAW_ARGS, NULL },
  580. { "DefaultType", set_string_slot,
  581.     (void*)XtOffsetOf (core_dir_config, default_type),
  582.     OR_FILEINFO, TAKE1, "the default MIME type for untypable files" },
  583.  
  584. /* Old server config file commands */
  585.  
  586. { "ServerType", server_type, NULL, RSRC_CONF, TAKE1,"'inetd' or 'standalone'"},
  587. { "Port", server_port, NULL, RSRC_CONF, TAKE1, "a TCP port number"},
  588. { "User", set_user, NULL, RSRC_CONF, TAKE1, "a username"},
  589. { "Group", set_group, NULL, RSRC_CONF, TAKE1, "a group name"},
  590. { "ServerAdmin", set_server_string_slot,
  591.   (void *)XtOffsetOf (server_rec, server_admin), RSRC_CONF, TAKE1,
  592.   "The email address of the server administrator" },
  593. { "ServerName", set_server_string_slot,
  594.   (void *)XtOffsetOf (server_rec, server_hostname), RSRC_CONF, TAKE1,
  595.   "The hostname of the server" },
  596. { "ServerRoot", set_server_root, NULL, RSRC_CONF, TAKE1, "a directory"},
  597. { "ErrorLog", set_server_string_slot,
  598.   (void *)XtOffsetOf (server_rec, error_fname), RSRC_CONF, TAKE1,
  599.   "the filename of the error log" },
  600. { "PidFile", set_pidfile, NULL, RSRC_CONF, TAKE1,
  601.     "a file for logging the server process ID"},
  602. { "AccessConfig", set_server_string_slot,
  603.   (void *)XtOffsetOf (server_rec, access_confname), RSRC_CONF, TAKE1,
  604.   "the filename of the access config file" },
  605. { "ResourceConfig", set_server_string_slot,
  606.   (void *)XtOffsetOf (server_rec, srm_confname), RSRC_CONF, TAKE1,
  607.   "the filename of the resource config file" },
  608. { "Timeout", set_timeout, NULL, RSRC_CONF, TAKE1, "timeout duration (sec)"},
  609. { "IdentityCheck", set_idcheck, NULL, RSRC_CONF, FLAG, NULL },
  610. { "CacheNegotiatedDocs", },
  611. { "StartServers", set_daemons_to_start, NULL, RSRC_CONF, TAKE1, NULL },
  612. { "MinSpareServers", set_min_free_servers, NULL, RSRC_CONF, TAKE1, NULL },
  613. { "MaxSpareServers", set_max_free_servers, NULL, RSRC_CONF, TAKE1, NULL },
  614. { "MaxServers", set_max_free_servers, NULL, RSRC_CONF, TAKE1, NULL },
  615. { "ServersSafetyLimit", set_server_limit, NULL, RSRC_CONF, TAKE1, NULL },
  616. { "MaxClients", set_server_limit, NULL, RSRC_CONF, TAKE1, NULL },
  617. { "MaxRequestsPerChild", set_max_requests, NULL, RSRC_CONF, TAKE1, NULL },
  618. { "BindAddress", set_bind_address, NULL, RSRC_CONF, TAKE1,
  619.   "'*', a numeric IP address, or the name of a host with a unique IP address"},
  620. { "<VirtualHost", virtualhost_section, NULL, RSRC_CONF, RAW_ARGS, NULL },
  621. { "</VirtualHost>", end_virtualhost_section, NULL, RSRC_CONF, NO_ARGS, NULL },
  622. { NULL },
  623. };
  624.  
  625. /*****************************************************************
  626.  *
  627.  * Core handlers for various phases of server operation...
  628.  */
  629.  
  630. int core_translate (request_rec *r)
  631. {
  632.     void *sconf = r->server->module_config;
  633.     core_server_config *conf = get_module_config (sconf, &core_module);
  634.   
  635.     if (r->uri[0] != '/') return BAD_REQUEST;
  636.     
  637.     r->filename = pstrcat (r->pool, conf->document_root, r->uri, NULL);
  638.     return OK;
  639. }
  640.  
  641. int do_nothing (request_rec *r) { return OK; }
  642.  
  643. /*
  644.  * Default handler for MIME types without other handlers.  Only GET
  645.  * at this point... anyone who wants to write a generic handler for
  646.  * PUT or POST is free to do so, but it seems unwise to provide any
  647.  * defaults yet...
  648.  */
  649.  
  650. int default_handler (request_rec *r)
  651. {
  652.     int errstatus;
  653.     FILE *f;
  654.     
  655.     if (r->method_number != M_GET) return DECLINED;
  656.     if (r->finfo.st_mode == 0 || (r->path_info && *r->path_info)) {
  657.     log_reason("File does not exist", r->filename, r);
  658.     return NOT_FOUND;
  659.     }
  660.     
  661.     if ((errstatus = set_content_length (r, r->finfo.st_size))
  662.     || (errstatus = set_last_modified (r, r->finfo.st_mtime)))
  663.         return errstatus;
  664.     
  665.     f = fopen (r->filename, "r");
  666.  
  667.     if (f == NULL) {
  668.         log_reason("file permissions deny server access", r->filename, r);
  669.         return FORBIDDEN;
  670.     }
  671.       
  672.     soft_timeout ("send", r);
  673.     
  674.     send_http_header (r);
  675.     if (!r->header_only) send_fd (f, r);
  676.     fclose (f);
  677.     return OK;
  678. }
  679.  
  680. handler_rec core_handlers[] = {
  681. { "*/*", default_handler },
  682. { NULL }
  683. };
  684.  
  685. module core_module = {
  686.    STANDARD_MODULE_STUFF,
  687.    NULL,            /* initializer */
  688.    create_core_dir_config,    /* create per-directory config structure */
  689.    merge_core_dir_configs,    /* merge per-directory config structures */
  690.    create_core_server_config,    /* create per-server config structure */
  691.    merge_core_server_configs,    /* merge per-server config structures */
  692.    core_cmds,            /* command table */
  693.    core_handlers,        /* handlers */
  694.    core_translate,        /* translate_handler */
  695.    NULL,            /* check_user_id */
  696.    NULL,            /* check auth */
  697.    do_nothing,            /* check access */
  698.    do_nothing,            /* type_checker */
  699.    NULL,            /* pre-run fixups */
  700.    NULL                /* logger */
  701. };
  702.